package com.sharp.core.raytrace.shading;

import com.sharp.core.graphics.Color;
import com.sharp.core.graphics.Light;
import com.sharp.core.graphics.Material;
import com.sharp.core.math.Vec3;
import com.sharp.core.math.Vectors3D;
import com.sharp.core.raytrace.Intersection;

public class DiffuseShading extends Shading {

	public DiffuseShading() {
	}
	
	@Override
	public Color calcColor(Intersection inter, Light light, Color c) {
		Material material = inter.getPrimitive().getMaterial();
		Vec3 N = inter.getPrimitive().normal(inter.getPos());
		//c.setTo( material.getColor() );

		Vec3 L = new Vec3(inter, light);
		L.normalize();
		float dot = Vectors3D.dotProduct(N, L);
		if ( dot < 0 )
			return new Color(Color.BLACK);
		float diff = dot * material.getDiffuse();
		Color kurva = new Color(material.getColor());
		kurva.multiply(diff);
		//c.add(kurva);
		return kurva;
	}

}
